import request from '@/utils/request';

export interface DeviceProfile {
  profileId: number;
  serialNumber: string | null;
  deviceName: string | null;
  deviceModel: string | null;
  supplier: string | null;
  department: string | null;
  purchasePrice: number | null;
  purchaseDate: string | null;
  createTime: string | null;
  updateTime: string | null;
  status: number | null;
}

export interface DeviceProfileListResponse {
  current: number;
  total: number;
  pages: number;
  size: number;
  records: DeviceProfile[];
}

export interface FormItemConfig {
  type: 'input' | 'datetime' | 'select'; 
  label: string;
  prop: keyof DeviceProfile;
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}

export interface DeviceProfileModel {
  isUpdate: boolean | null;
  profileId: number | null;
  serialNumber: string | null;
  deviceName: string | null;
  deviceModel: string | null;
  supplier: string | null;
  department: string | null;
  purchasePrice: number | null;
  purchaseDate: string | null;
  status: number | null;
}

export const deviceProfileApi = {
  getDeviceProfileList: (params: any) => {
    return request<DeviceProfileListResponse>({
      method: 'GET',
      url: `/procedure/deviceProfiles`,
      params: params
    });
  },

  addDeviceProfile: (data: DeviceProfileModel) => {
    return request<String>({
      method: 'POST',
      url: `/procedure/deviceProfiles`,
      data: data
    });
  },

  updateDeviceProfile: (id: number, data: DeviceProfileModel) => {
    return request<String>({
      method: 'PUT',
      url: `/procedure/deviceProfiles/${id}`,
      data: data
    });
  },

  deleteDeviceProfile: (id: number) => {
    return request<String>({
      method: 'DELETE',
      url: `/procedure/deviceProfiles/${id}`,
    });
  },
};


export const deviceStatusMap = {
  1: '运行中',
  2: '空闲',
  3: '故障待维修',
  4: '维修中',
  5: '已报废',
  6: '已注销',
  7: '维护中',
} as const;

export const getDeviceStatusLabel = (value: any): string => {
  return deviceStatusMap[value as keyof typeof deviceStatusMap] || '未知状态';
};

